package org.hs.phd.odi.tracking.tracker.particlefilter.state;

import java.awt.Polygon;
import java.awt.Rectangle;

import org.hs.phd.odi.tracking.tracker.TrackerUtils;

public class RotatedRectangleParticleState{
	
	public final float x; /**< current x coordinate */
	public final float y; /**< current y coordinate */
	public final float scale; /**< scale */
	public final int initialWidth; /**< original width of region described by particle */
	public final int initialHeight; /**< original height of region described by particle */
	public final float rotationAngleRadians;
	
	public RotatedRectangleParticleState(float x, float y, int width, int height) {
		this(x, y, width, height, 1, 0);
	}

	public RotatedRectangleParticleState(float x, float y, int width, int height, float s) {
		this(x, y, width, height, s, 0);
	}

	public RotatedRectangleParticleState(float x, float y, int width, int height, float s, float rotationAngleRadians) {
		this.x = x;
		this.y = y;
		this.initialWidth = width;
		this.initialHeight = height;
		this.scale = s;
		this.rotationAngleRadians = rotationAngleRadians;
	}

	public RotatedRectangleParticleState(Rectangle rect) {
		this( rect.x + 0.5F*rect.width, 
			  rect.y + 0.5F*rect.height,
		      rect.width, rect.height, 1, 0 );
	}

	public Polygon getShape() {
		int newWidth = Math.round(scale * initialWidth);
		int newHeight = Math.round(scale * initialHeight);
		int newX = Math.round(x - 0.5F * scale * initialWidth);
		int newY = Math.round(y - 0.5F * scale * initialHeight);
		 
		return TrackerUtils.getAsPolygon(new Rectangle(newX,newY,newWidth,newHeight));
	}

	public RotatedRectangleParticleState createMovedScaledCopy(float newX, float newY, float newScale) {
		  return new RotatedRectangleParticleState(newX, newY, initialWidth, initialHeight, newScale, rotationAngleRadians);
	}
	
	
	
	
	
}
